package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Xzqh;
import com.ruoyi.system.service.IXzqhService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 行政区划信息Controller
 * 
 * @author zbb
 * @date 2023-02-13
 */
@Controller
@RequestMapping("/xzqh/xzqh")
public class XzqhController extends BaseController
{
    private String prefix = "xzqh/xzqh";

    @Autowired
    private IXzqhService xzqhService;

    @RequiresPermissions("xzqh:xzqh:view")
    @GetMapping()
    public String xzqh()
    {
        return prefix + "/xzqh";
    }

    /**
     * 查询行政区划信息树列表
     */
    @RequiresPermissions("xzqh:xzqh:list")
    @PostMapping("/list")
    @ResponseBody
    public List<Xzqh> list(Xzqh xzqh)
    {
        List<Xzqh> list = xzqhService.selectXzqhList(xzqh);
        return list;
    }

    /**
     * 导出行政区划信息列表
     */
    @RequiresPermissions("xzqh:xzqh:export")
    @Log(title = "行政区划信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Xzqh xzqh)
    {
        List<Xzqh> list = xzqhService.selectXzqhList(xzqh);
        ExcelUtil<Xzqh> util = new ExcelUtil<Xzqh>(Xzqh.class);
        return util.exportExcel(list, "行政区划信息数据");
    }

    /**
     * 新增行政区划信息
     */
    @GetMapping(value = { "/add/{xzqhId}", "/add/" })
    public String add(@PathVariable(value = "xzqhId", required = false) Long xzqhId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(xzqhId))
        {
            mmap.put("xzqh", xzqhService.selectXzqhByXzqhId(xzqhId));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存行政区划信息
     */
    @RequiresPermissions("xzqh:xzqh:add")
    @Log(title = "行政区划信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Xzqh xzqh)
    {
        return toAjax(xzqhService.insertXzqh(xzqh));
    }

    /**
     * 修改行政区划信息
     */
    @RequiresPermissions("xzqh:xzqh:edit")
    @GetMapping("/edit/{xzqhId}")
    public String edit(@PathVariable("xzqhId") Long xzqhId, ModelMap mmap)
    {
        Xzqh xzqh = xzqhService.selectXzqhByXzqhId(xzqhId);
        mmap.put("xzqh", xzqh);
        return prefix + "/edit";
    }

    /**
     * 修改保存行政区划信息
     */
    @RequiresPermissions("xzqh:xzqh:edit")
    @Log(title = "行政区划信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Xzqh xzqh)
    {
        return toAjax(xzqhService.updateXzqh(xzqh));
    }

    /**
     * 删除
     */
    @RequiresPermissions("xzqh:xzqh:remove")
    @Log(title = "行政区划信息", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{xzqhId}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("xzqhId") Long xzqhId)
    {
        return toAjax(xzqhService.deleteXzqhByXzqhId(xzqhId));
    }

    /**
     * 选择行政区划信息树
     */
    @GetMapping(value = { "/selectXzqhTree/{xzqhId}", "/selectXzqhTree/" })
    public String selectXzqhTree(@PathVariable(value = "xzqhId", required = false) Long xzqhId, ModelMap mmap)
    {
        if (StringUtils.isNotNull(xzqhId))
        {
            mmap.put("xzqh", xzqhService.selectXzqhByXzqhId(xzqhId));
        }
        return prefix + "/tree";
    }

    /**
     * 加载行政区划信息树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = xzqhService.selectXzqhTree();
        return ztrees;
    }
}
